package com.roadjava.rbac.config;

import com.roadjava.rbac.config.properties.UploadProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;


@Configuration
@EnableConfigurationProperties(value = UploadProperties.class)
public class StorageConfig implements WebMvcConfigurer {
    @Resource
    private UploadProperties uploadProperties;
    /**
     * 静态资源的位置增加指定的file目录
     * http://localhost:8000/resources/images/20240601/123.jpg
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String[] locations = { "classpath:/META-INF/resources/",
                "classpath:/resources/", "classpath:/static/", "classpath:/public/",
                // 自定义的本地路径
                "file:"+ uploadProperties.getStaticDir()};
        registry.addResourceHandler("/**")
                .addResourceLocations(locations);
    }

}
